package com.mp3s.plugin_quote.full.utils;

import java.util.ArrayList;
import java.util.List;

import com.mp3s.interface3.QuoteData;

import cn.hutool.core.util.StrUtil;

public class utils {

    public static QuoteData parseOne(String out){
      List<String> o1 = StrUtil.split(out, ',');
      if(o1.size() < 3){
        return null;
      }
      // System.out.println(out);
      int idx = 0;
      QuoteData q0 = new QuoteData();
      String name = o1.get(idx);
      idx++;
      String fix = "var hq_str_sh000000=\"";    //中文名
      String name1 = StrUtil.subSuf(name, fix.length());
      q0.setCnName(name1);
      String fix2 = "var hq_str_";  //stockId
      fix = "var hq_str_sh000000";
      String name2 = StrUtil.sub(name, fix2.length(),fix.length());
      q0.setName(name2);
      String open = o1.get(idx);
      q0.setOpen(open);
      idx++;
      String lastClose = o1.get(idx);
      q0.setLastClose(lastClose);
      idx++;
      String newP = o1.get(idx);
      q0.setClose(newP);
      idx++;
      String high = o1.get(idx);
      q0.setHigh(high);
      idx++;
      String low = o1.get(idx);
      q0.setLow(low);
      idx++;
      //空2个
      idx += 2;
      String volume = o1.get(idx);
      q0.setVolume(volume);
      //空22个,指定时间
      idx += 22;
      String d1 = o1.get(idx);
      q0.setDate(d1);
      // System.out.println(q0.toString());
      return q0;
    }

    public static List<QuoteData> parseSinaQuote(String out){
		  // System.out.println("parseSinaQuote");
          List<QuoteData> LQ = new ArrayList<>();
          List<String> o2 = StrUtil.split(out, '\n');
          for(String item:o2){
            QuoteData q1 = parseOne(item);
            if(q1 != null){
              LQ.add(q1);
              // JSONObject json = JSONUtil.parseObj(q1, false);
              // System.out.println(json);
            }
          }          
          System.out.println(LQ.toString());        

          return LQ;
    }
}
